package com.ld.campus_help.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ld.campus_help.entity.Lost;
import com.ld.campus_help.entity.Unused;
import com.ld.campus_help.mapper.LostMapper;
import com.ld.campus_help.mapper.ServeMapper;
import com.ld.campus_help.service.LostService;
import com.ld.campus_help.service.ServeService;
import com.ld.campus_help.util.Result;
import com.ld.campus_help.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/lost")
public class LostController {
    @Autowired
    private LostMapper lostMapper;
    @Autowired
    private LostService lostService;

    @Autowired
    private ServeMapper serveMapper;
    @Autowired
    private ServeService serveService;

//    @GetMapping("/list/{schoolId}")
//    public Result getLostList(@PathVariable("schoolId") Integer schoolId){
    /*
        1.get请求参数
        2.返回list
     */
    @GetMapping("/list")
    public Result getLostList(){
        List<Lost> result = lostService.getList();
        if(result != null) return ResultUtil.success(result);
        return ResultUtil.failure();
    }

    @PostMapping("/statusList")
    public Result getStatusList(@RequestBody Lost lost){
        List<Lost> result = lostService.getList(lost);
        if (result != null) return ResultUtil.success(result);
        return ResultUtil.failure();
    }

    @GetMapping("deleteLost")
    public Result deleteUnused(){
        QueryWrapper<Lost> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", 2);
        Lost deleted = lostService.getOne(queryWrapper);
        if(deleted != null) {
            lostService.remove(queryWrapper);
            serveService.saveLost(deleted);
            return ResultUtil.success();
        }
        return ResultUtil.failure();
    }


}
